﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserManager.aspx.cs" Inherits="Web.Admin.UserControl.UserManager" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="../../Styles/Common.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Common.js" type="text/javascript"></script>
    <script src="../../Scripts/WebInner.js" type="text/javascript"></script>
    <script src="../../Scripts/Zebra/zebra_dialog.js" type="text/javascript"></script>
    <link href="../../Scripts/Zebra/zebra_dialog.css" rel="stylesheet" type="text/css" />
    <style type="text/css">

</style>
    <script type="text/javascript">
   
        $(function () {
            //显示网点类型,操作级别
            $.ajax({
                url: '/Admin/UserControl/user.ashx?type=GetWB',
                type: 'post',
                data: '',
                dataType: 'json',
                success: function (r) {
                    for (var i = 0; i < r.length; i++) {
                        $('select[name=WB_ID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");

                    }
                    GetUserGroupByWBID(r[0].ID);
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>加载网点类别失败 ！</strong>');
                }
            });

            $('select[name=WB_ID]').change(function () {
                GetUserGroupByWBID($('select[name=WB_ID] option:selected').val());
            });


        });

        //根据网点加载用户组级别（只有总部人员可以成为网店管理员和单位管理员）
        function GetUserGroupByWBID(WBID) {
            $('select[name=UserGroup_ID]').empty();
            $.ajax({
                url: '/Admin/UserControl/user.ashx?type=GetUserGroup&WBID=' + WBID,
                type: 'post',
                data: '',
                dataType: 'json',
                success: function (r) {
                    for (var i = 0; i < r.length; i++) {
                        $('select[name=UserGroup_ID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                    }
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>加载操作级别失败 ！</strong>');
                }
            });
        }

        function ShowFrm(userID) {
            $('#divfrm').fadeIn("normal");
            var wbid = $('select[name=WB_ID] option:selected').val();
            $('select[name=WB_ID]').removeAttr('disabled');
            GetUserGroupByWBID(wbid); //根据网点类型判定要加载的营业员类型
            $('#trAdd').fadeIn("fast");
            $('#trUpdate').fadeOut("fast");
            $('input[name=strRealName]').val('');
            $('input[name=strLoginName]').val('');
            $('input[name=strPassword]').val('');
            $('input[name=strPhone]').val('');
            $('input[name=strAddress]').val('');
            $('input[name=numLimitAmount]').val('');
            $('select[name=ISEnable]').val('1');
        }

        function ShowFrmEdit(id, wbid, UserGroup_ID) {
            $('#divfrm').fadeIn("normal");
            $('#ID').val(id);
            $('select[name=WB_ID]').attr('disabled', 'disabled');
            $('#UserGroup_ID').val(UserGroup_ID);
            if (UserGroup_ID == "网点管理员" || UserGroup_ID == "营业员") {
                $('#btnMenu').removeAttr('disabled');
            } else {
                $('#btnMenu').attr('disabled','disabled');
            }
          
            GetUserGroupByWBID(wbid); //根据网点类型判定要加载的营业员类型

            $('#trAdd').fadeOut("fast");
            $('#trUpdate').fadeIn("fast");
            
            /*--------数据提交--------*/
            $.ajax({
                url: '/Admin/UserControl/user.ashx?type=GetUserByID&ID=' + id,
                type: 'post',
                data: '',
                dataType: 'json',
                success: function (r) {

                    $("select[name=WB_ID]  option[value='" + r[0].WB_ID + "'] ").attr("selected", 'selected');

                    $('input[name=strRealName]').val(r[0].strRealName);
                    $('input[name=strLoginName]').val(r[0].strLoginName);
                    //                         $('input[name=strPassword]').val(r[0].strPassword);
                    //                         $('input[name=strPassword2]').val(r[0].strPassword);
                    $('input[name=strPhone]').val(r[0].strPhone);
                    $('input[name=strAddress]').val(r[0].strAddress);
                    $('input[name=numLimitAmount]').val(r[0].numLimitAmount);

                    // $("select[name=UserGroup_ID]option[value='" + r[0].UserGroup_ID + "'] ").attr("selected", 'selected');
                    $("select[name=UserGroup_ID]").val(r[0].UserGroup_ID);
                    if (r[0].ISEnable) {
                        $("select[name=ISEnable]  option[value='1'] ").attr("selected", 'selected');
                    } else {
                        $("select[name=ISEnable]  option[value='0'] ").attr("selected", 'selected');
                    }
                }
            });
        }

        function CloseFrm() {
            $('#divfrm').fadeOut("normal");
        }

        //添加、修改网点 （ID=0是添加网点）
        function WBAdd() {
            if (!SubmitCheck()) {//检测输入内容
                return false;
            }
            if (confirm("您确认已经仔细检查输入信息，并继续操作吗？")) {
                var strurl = '/Admin/UserControl/user.ashx?type=AddUser&ID=0'
                if ($('input[name=strPassword]').val() == "") {
                    $.Zebra_Dialog('<strong>请输入密码 ！</strong>');
                    $('input[name=strPassword]').focus();
                    return false;
                }
                if ($('input[name=strPassword2]').val() == "") {
                    $.Zebra_Dialog('<strong>请输入确认密码 ！</strong>');
                    $('input[name=strPassword2]').focus();
                    return false;
                }
                if ($('input[name=strPassword]').val() != $('input[name=strPassword2]').val()) {
                    $.Zebra_Dialog('<strong>两次输入的密码不一致，请检查 ！</strong>');
                    $('input[name=strPassword2]').focus();
                    return false;
                }
                /*--------数据提交--------*/
                $.ajax({
                    url: strurl,
                    type: 'post',
                    data: $('#form1').serialize(),
                    dataType: 'txt',
                    success: function (r) {
                        if (r == "OK") {
                            $.Zebra_Dialog('<strong>添加网点营业员成功 ！</strong>');
                            location.reload();
                        } else if (r == "1") {
                            $.Zebra_Dialog('<strong>已存在相同的用户登陆名，请修改后添加 ！</strong>');
                        }
                    }, error: function (r) {
                        $.Zebra_Dialog('<strong>添加营业员失败 ！</strong>');
                    }
                });
                /*--------End 数据提交--------*/
               
            }
        }

        //添加、修改网点 （ID=0是添加网点）
        function WBUpdate() {
            if (!SubmitCheck()) {//检测输入内容
                return false;
            }
          
            var ID = $('#ID').val();
            if (confirm("您确认已经仔细检查输入信息，并继续操作吗？")) {
                var strurl = '/Admin/UserControl/user.ashx?type=UpdateUser&ID=' + ID;
                
                /*--------数据提交--------*/
                $.ajax({
                    url: strurl,
                    type: 'post',
                    data: $('#form1').serialize(),
                    dataType: 'txt',
                    success: function (r) {
                        if (r == "OK") {
                            $.Zebra_Dialog('<strong>更新营业员信息成功 ！</strong>');
                            location.reload();
                        } 
                    }, error: function (r) {
                        $.Zebra_Dialog('<strong>更新营业员信息失败 ！</strong>');
                    }
                });
               
            }
        }

        //提交检测
        function SubmitCheck() {
            if ($('input[name=strRealName]').val() == "") {
                $.Zebra_Dialog('<strong>请输入真实姓名 ！</strong>');
                $('input[name=strRealName]').focus();
                return false;
            }
            if ($('input[name=strLoginName]').val() == "") {
                $.Zebra_Dialog('<strong>请输入登陆名 ！</strong>');
                $('input[name=strLoginName]').focus();
                return false;
            }
         
            if (!CheckInput('strPhone', '手机号', -1)) {
                return false;
            }
            if (!CheckInput('strAddress', '联系地址', -1)) {
                return false;
            }

            if (isNaN($('input[name=numLimitAmount]').val())) {
                $.Zebra_Dialog('<strong>支取额度请输入数字 ！</strong>');
                $('input[name=numLimitAmount]').focus();
                return false;
            }
            return true;

        }


        function WBDelete() {
            var ID = $('#ID').val();
            if (confirm("您确认要删除此营业员/管理员吗？")) {
                /*--------数据提交--------*/
                $.ajax({
                    url: '/Admin/UserControl/user.ashx?type=DeleteUserByID&ID=' + ID,
                    type: 'post',
                    data: '',
                    dataType: 'txt',
                    success: function (r) {
                        if (r == "OK") {
                            $.Zebra_Dialog('<strong>删除数据成功！</strong>');
                            CloseFrm();
                            location.reload();
                        } else {
                            $.Zebra_Dialog('<strong>删除数据失败 ！</strong>');
                        }
                    }, error: function (r) {
                        $.Zebra_Dialog('<strong>删除数据失败 ！</strong>');
                    }
                });
                /*--------End 数据提交--------*/

            }
        }


        //打开菜单编辑窗口
        function FunMenu(ID, UserGroup_ID) {

            var numtype = 1;
            if (UserGroup_ID == "单位管理员") {
                return false;
            }
            else if (UserGroup_ID == "营业员") {
             numtype = 2;
            }
            var left = accDiv(window.screen.width, 2) - 300;
            var top = 100;
            window.open('UserMenu.aspx?UserID='+ID+'&numtype='+numtype, '营业员权限编辑', 'height=600,width=600,top='+top+',left='+left+',toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no') 
        }

     
    </script>
</head>
<body>
     <form id="form1" runat="server">
<div class="pageHead">
<b>营业员(会计)管理</b>
</div>

<div class="QueryHead">
<table>
            <tr>
            <td><span>按营业员名称查询:</span></td>
            <td><span><input type="text" id="txtType" runat="server" /> </s </span></td>
            <td style="width:60px">
                <asp:ImageButton ID="ImageButton1" runat="server" 
                    ImageUrl="~/images/seach_brown.png" onclick="ImageButton1_Click"  />
                </td>
            <td><%=GetAddItem() %></td>
            </tr>
            
        </table>
</div>
<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <table  class="tabData" style="width:900px">
          <tr class="tr_head" >
                <th style="width:100px; text-align:center;">
                    网点名称</th>
                <th style="width:100px; text-align:center;">
                    营业员编号</th>
                <th style="width:100px; text-align:center;">
                    真实姓名</th>
                <th style="width:100px; text-align:center;">
                    登录名</th>
                    <th style="width:100px; text-align:center;">
                    级别</th>
                    <th style="width:100px; text-align:center;">
                    状态</th>
                    <th style="width:120px; text-align:center;">
                    查看/修改</th>
                     <th style="width:120px; text-align:center;">
                    权限管理</th>
                
            </tr>
        
    </HeaderTemplate>
    <ItemTemplate>
    <tr style='background-color: <%#(Container.ItemIndex%2==0)?"#FFFFF;":"#fcf3f4"%>' onmouseover="change_colorOver(this)" onmouseout="change_colorOut(this)">
        <td><%#Eval("WBName")%></td>
        <td><%#Eval("SerialNumber")%></td>
        <td><%#Eval("strRealName")%></td>
        <td><%#Eval("strLoginName")%></td>
        <td><%#Eval("UserGroup_ID")%></td>
        <td><%#Eval("ISEnable")%></td>
        <td>
        <%#GetUpdateItem(Eval("ID"),Eval("WBID"),Eval("UserGroup_ID")) %>
       </td>
        <td>
        <%#GetAnthorityItem(Eval("ID"),Eval("UserGroup_ID")) %>
        </td>
   
    </tr>
    </ItemTemplate>
    
    <FooterTemplate><!--底部模板-->
        </table>        <!--表格结束部分-->
        </FooterTemplate>
    </asp:Repeater>
     <webdiyer:AspNetPager ID="AspNetPager1" runat="server"
             FirstPageText="首页" LastPageText="尾页"  PrevPageText="上一页" NextPageText="下一页" 
        NumericButtonTextFormatString="[{0}]" PageSize="15" onpagechanging="AspNetPager1_PageChanging" 
               >
            </webdiyer:AspNetPager>
    <div  id="divfrm" class="pageEidt" style="display:none; width:410px; height:420px;">
    <div style="float:right; margin:10px 20px"> <img src="../../images/winClose.png" alt="关闭窗口"  style="float:right; cursor:pointer;" onclick="CloseFrm()" /></div>    
   
    <div style="clear:both;">
        <table >
            
            <tr>
            <td align="right" style="width:90px;"><span>所属网点:</span></td>
            <td><select name="WB_ID" style="width:160px; height:25px"></select></td>
            </tr>
            <tr>
            <td align="right"><span>操作级别:</span></td>
            <td><select name="UserGroup_ID" style="width:160px; height:25px"></select></td>
            </tr>
             <tr>
            <td align="right"><span>真实姓名:</span></td>
            <td><input type="text" style="width:150px;" name="strRealName" />
            <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">必填</span>
            </td>
            </tr>
             <tr>
             <td align="right"><span>登录名:</span></td>
            <td><input type="text" style="width:150px;"  name="strLoginName" />  <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">必填</span></td>
            </tr>
             <tr>
            <td align="right"><span>登录密码:</span></td>
            <td><input type="password" style="width:150px;"  name="strPassword" />
              <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">英文与数字，至少四位</span>
            </td>
            </tr>
             <tr>
            <td align="right"><span>确认密码:</span></td>
            <td><input type="password" style="width:150px;"  name="strPassword2" />
             <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">再次输入密码</span>
            </td>
            </tr>
            <tr>
           <td align="right"><span>手机:</span></td>
            <td><input type="text" style="width:150px;"  name="strPhone" />
             <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">必填</span>
            </td>
            </tr>
            <tr>
            <td align="right"><span>住址:</span></td>
            <td><input type="text" style=" width:240px;"  name="strAddress" />
            <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">必填</span>
            </td>
            </tr>
            <tr>
            <td align="right"><span>支取额度:</span></td>
            <td><input type="text" style="width:100px;"  name="numLimitAmount" />元
            <span style="color:Red; font-weight:bolder;">*</span><span style="font-size:12px;">必填</span>
            </td>
            </tr>
            
            
            <tr>
             <td align="right"><span>使用状态:</span></td>
            <td><select name="ISEnable" style="width:110px; height:25px">
            <option value="1" selected="selected">启用</option>
             <option value="0" >禁用</option>
            </select></td>
            </tr>
            <tr id="trAdd">
            <td></td>
            <td ><input type="button" id="btnAdd" value="添加" onclick="WBAdd()" /> </td>
            </tr>
               <tr id="trUpdate">
            <td></td>
            <td ><input type="button" id="btnUpdate" value="修改" style="width:80px;" onclick="WBUpdate()" />&nbsp;&nbsp;
        <%--    <input type="button" id="btnDel" value="删除" onclick="WBDelete()" />&nbsp;&nbsp;--%>
     <%--   <input type="button" id="btnMenu" value="权限管理" disabled="disabled" style="width:120px;" onclick="FunMenu()" />--%>
             </td>
            </tr>
        </table>
        </div>
    </div>

    </form>
    <%--定义编号--%>
    <input type="hidden" id="ID" value="" />
    <input type="hidden" id="UserGroup_ID" value="" />
    <%--定义背景色的隐藏域--%>
    <input type="hidden" id="colorName" value="" />
</body>
</html>
